package question

import "sort"

//2341. 数组能形成多少数对
func numberOfPairs(nums []int) []int {
	n := len(nums)
	if n < 2 {
		return []int{0, n}
	}
	sort.Ints(nums)
	count := 0
	temp := n
	index := 0
	for index < n-1 {
		if nums[index] == nums[index+1] {
			count += 1
			temp -= 2
			index += 2
		} else {
			index++
		}
	}
	return []int{count, temp}
}
